﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace App.Controllers.CMS
{
    public class ContentController : Controller
    {
        //
        // GET: /Content/

        public ActionResult Index()
        {
            return View("~/Views/CMS/Content/Index.cshtml");
        }

        public HtmlString ImgUpload()
        {
            if( Request.Files.Count>0)
            {
                var exts = new string[] {".img", ".jpg", ".jpeg", ".bmp"};
                var file = Request.Files[0];
                var ext = Path.GetExtension(file.FileName).ToLower();
                if(exts.Any(u=>u==ext))
                {
                    var filename = DateTime.Now.ToString("yyyyMMddHHmmssfff");
                    string path = @"~/Files/" + filename + ext;
                    path = System.Web.HttpContext.Current.Server.MapPath(path);
                    file.SaveAs(path);
                    return new HtmlString("<script type=\"text/javascript\">window.parent.CKEDITOR.tools.callFunction('.$fn.', \''.$fileurl.'\', \''.$message.'\');</script>");
                }
                return new HtmlString("文件类型不对");
            }
            return new HtmlString("请选择图片");
        }

    }
}
